package javax;

/**
 * Created by xupeng20 on 2019/1/15.
 */
public class Demo {
    public static void main(String[] args){
        int num = 14 ;
        System.out.println(11%10);

        int[] arr1 = {1,3,3};
        int[] arr2 = {1,4,6};
        int kth = findKth(arr1, 0, arr1.length - 1, arr2, 0, arr2.length - 1, 6);

        System.out.println(kth);
    }



    private static int findKth(int[] array1, int start1, int end1, int[] array2, int start2, int end2, int k){
        if(start1>end1){
            return array2[start2+k-1];
        }
        if(start2>end2){
            return array1[start1+k-1];
        }
        if(k==1){
            return Math.min(array1[start1], array2[start2]);
        }
        int mid1=Integer.MAX_VALUE;
        int mid2=Integer.MAX_VALUE;
        //这里的思想，其实不是每次移动整个end-start的一半，而是移动k的一半
        if(start1+k/2-1<=end1){
            mid1=array1[start1+k/2-1];
        }
        if(start2+k/2-1<=end2){
            mid2=array2[start2+k/2-1];
        }
        if(mid1<mid2){
            return findKth(array1, start1+k/2, end1, array2, start2, end2, k-k/2);
        }
        return findKth(array1, start1, end1, array2, start2+k/2, end2, k-k/2);
    }


}
